package wenjun.du.androidart


import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import kotlinx.android.synthetic.main.activity_main.*
import wenjun.du.androidart.activity.NormalActivity
import wenjun.du.androidart.animator.AnimatorActivity
import wenjun.du.androidart.component.ComponentActivity
import wenjun.du.androidart.drawable.DrawableActivity
import wenjun.du.androidart.handler.HandlerActivity
import wenjun.du.androidart.ipc.IpcActivity
import wenjun.du.androidart.remoteview.RemoteViewsActivity
import wenjun.du.androidart.threadPool.ThreadPoolActivity
import wenjun.du.androidart.view.ViewActivity
import wenjun.du.androidart.view.ViewAnimatorActivity
import wenjun.du.androidart.viewcreate.ViewCreateActivity
import wenjun.du.androidart.window.WindowActivity


class MainActivity : AppCompatActivity() {
    companion object {
        private const val TAG = "MainActivity"
    }

    private lateinit var mAdapter: FruitAdapter
    private val classList = mutableListOf<Fruit>(
        Fruit("Activity", R.drawable.summer, NormalActivity::class.java),
        Fruit("跨进程通讯", R.drawable.animal, IpcActivity::class.java),
        Fruit("View touch 传递", R.drawable.animal, ViewActivity::class.java),
        Fruit("View 绘制过程", R.drawable.summer, ViewCreateActivity::class.java),
        Fruit("RemoteView", R.drawable.summer, RemoteViewsActivity::class.java),
        Fruit("Drawable", R.drawable.animal, DrawableActivity::class.java),
        Fruit("属性动画", R.drawable.summer, AnimatorActivity::class.java),
        Fruit("window", R.drawable.animal, WindowActivity::class.java),
        Fruit("Component", R.drawable.summer, ComponentActivity::class.java),
        Fruit("Handler", R.drawable.animal, HandlerActivity::class.java),
        Fruit("ThreadPool", R.drawable.summer, ThreadPoolActivity::class.java),
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setRecycleView()
    }


    /**
     * 创建一个格式布局 加载图片和文字方格
     *
     * */
    private fun setRecycleView() {
        val layoutManger = GridLayoutManager(this, 2)
        main_contain.layoutManager = layoutManger
        if (!::mAdapter.isInitialized) {
            mAdapter = FruitAdapter(this, classList)
        }
        main_contain.adapter = mAdapter

    }
}